package com.example.websocketdemo.controller;

import com.alibaba.fastjson.JSONArray;
import com.alibaba.fastjson.JSONObject;
import com.example.websocketdemo.config.WebSocketTest;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import javax.servlet.http.HttpServletResponse;
import java.io.IOException;

@RestController
@RequestMapping("/personnel")
public class PersonnelLocationController {

    @GetMapping("/message")
    public void p(HttpServletResponse response) throws IOException {
        response.setHeader("Access-Control-Allow-Origin", "*");
        JSONObject jsonObject = new JSONObject();
        JSONObject json = new JSONObject();
        JSONObject xinxi = new JSONObject();
        JSONObject xinxi1 = new JSONObject();

        JSONArray Array = new JSONArray();
        jsonObject.put("instruction", "updatepoi");
        json.put("updatetype", "resetrenyuan");
        json.put("poigroup", "anbao");
        json.put("poitype", "anbao");

        xinxi.put("用户Id", "192");
        xinxi.put("姓名", "唐勇");
        xinxi.put("部门", "安保部");
        xinxi.put("手机号", "13333000000");
        xinxi.put("X", "-7789");
        xinxi.put("Y", "1500");

        xinxi1.put("用户Id","191");
        xinxi1.put("姓名","郑磊");
        xinxi1.put("部门","C班");
        xinxi1.put("手机号","13127559873");
        xinxi1.put("X","-6100");
        xinxi1.put("Y","1234");
        Array.add(xinxi);
        Array.add(xinxi1);
        json.put("Array", Array);
        jsonObject.put("param", json);


        JSONObject jsonObject2 = new JSONObject();
        JSONObject json2 = new JSONObject();
        jsonObject2.put("instruction", "showpoi");
        json2.put("showtype", "dygroup");
        json2.put("poigroup", "anbao");
        json2.put("poitype", "anbao");
        jsonObject2.put("param", json2);

        JSONObject jsonObject_one = new JSONObject();
        jsonObject_one.put("instruction","resetpoi");
        WebSocketTest.sendInfo(jsonObject_one.toJSONString(), "connect");

        for (int i = 0; i < 2; i++) {
            if (i == 0) {
                WebSocketTest.sendInfo(jsonObject.toJSONString(), "connect");
            } else {
                WebSocketTest.sendInfo(jsonObject2.toJSONString(), "connect");
            }
        }
    }
}
